/*
 *    This file is part of BlobDB.
 *
 *    BlobDB is free software: you can redistribute it and/or modify
 *    it under the terms of the GNU General Public License as published by
 *    the Free Software Foundation, either version 3 of the License, or
 *    (at your option) any later version.
 *
 *    BlobDB is distributed in the hope that it will be useful,
 *    but WITHOUT ANY WARRANTY; without even the implied warranty of
 *    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *    GNU General Public License for more details.
 *
 *    You should have received a copy of the GNU General Public License
 *    along with BlobDB.  If not, see <http://www.gnu.org/licenses/>.
 *    
 *    Copyright(c) 2011 Michael Kankkonen
 *    http://www.vnetcon.org
 */


package org.vnetcon.blobdb.driver.jdbc;

import java.net.URL;
import java.sql.Connection;
import java.sql.Driver;
import java.sql.DriverManager;
import java.sql.DriverPropertyInfo;
import java.sql.SQLException;
import java.util.Properties;

public class BlobDBDriver implements Driver {

	private int MAJOR_VERSION = 0;
	private int MINOR_VERSION = 7;

	private String strWsUrl = null;
	private String username = "username";
	private String password = "password";
	private URL urlWsUrl = null;

	
	public BlobDBDriver() throws SQLException{
		DriverManager.registerDriver(this);
	}
	
	/**
	 * Syntax for url: blobdb|WebServiceUrl|username=username|password=password|proxy=http://proxy:port
	 * Example: blobdb|http://localhost:8888/blobdb/ws
	 * 
	 */
	@Override
	public boolean acceptsURL(String connectionString) throws SQLException {
		if(connectionString.equals("blobdb")){
			return true;
		}
		return false;
	}

	
	@Override
	public Connection connect(String connectionString, Properties arg1) throws SQLException {
		org.vnetcon.blobdb.database.Statement nativeStatement = null;
		try {
			nativeStatement = new org.vnetcon.blobdb.database.Statement();
		} catch (Exception e) {
			e.printStackTrace();
			throw new SQLException(e.getMessage());
		}
		BlobDBConnection retCon = new BlobDBConnection(nativeStatement);
		return retCon;
	}

	@Override
	public int getMajorVersion() {
		return this.MAJOR_VERSION;
	}

	@Override
	public int getMinorVersion() {
		return this.MINOR_VERSION;
	}

	@Override
	public DriverPropertyInfo[] getPropertyInfo(String arg0, Properties arg1)
			throws SQLException {
		throw new SQLException("Not implemented.");
	}

	@Override
	public boolean jdbcCompliant() {
		return false;
	}

}
